﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Security;
using System.Collections;

namespace IronOne.SalesOne.SalesOneWeb.UserControls
{
    public partial class UCUserGrid : System.Web.UI.UserControl
    {
        private int[] hideColumns;


        #region Public Properties

        public int[] HideColumns
        {
            get { return hideColumns; }
            set { Session["hideCols"] = value; }
        }


        #endregion


        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #region Set Data Source To Grid

        public void SetDataSource(DataTable tbl)
        {
            grdUsers.DataSource = tbl;
            grdUsers.DataBind();
        }

        public void SetDataSource(DataTable tbl, int[] hideIndex)
        {
            Session["hideCols"] = hideIndex;
            grdUsers.DataSource = tbl;
            grdUsers.DataBind();
        }

        public void SetDataSource(DataSet ds)
        {
            grdUsers.DataSource = ds;
            grdUsers.DataBind();
        }

        public void SetDataSource(DataSet ds, int[] hideIndex)
        {
            Session["hideCols"] = hideIndex;
            grdUsers.DataSource = ds;
            grdUsers.DataBind();
        }

        public void SetDataSource(ICollection coll)
        {
            grdUsers.DataSource = coll;
            grdUsers.DataBind();
        }

        public void SetDataSource(ICollection coll, int[] hideIndex)
        {
            Session["hideCols"] = hideIndex;
            grdUsers.DataSource = coll;
            grdUsers.DataBind();
        }

        #endregion




        public bool SetVisible
        {
            set
            {
                grdUsers.Visible = value;
            }
        }


        protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
        {
            string pageUrl = Request.ServerVariables["URL"];

            foreach (GridViewRow row in grdUsers.Rows)
            {
                RadioButton rbtn = (RadioButton)row.FindControl("RadioButton1");

                if (rbtn != null)
                {
                    if ((rbtn.ClientID.ToString() == ((RadioButton)sender).ClientID.ToString()))
                    {
                        //Session[pageUrl + "view"] = row.Cells[2].Text;

                        if (this.Page is IDataPage)
                            ((IDataPage)this.Page).GetId(row);
                        rbtn.Checked = true;
                    }
                    else
                    {
                        rbtn.Checked = false;
                    }


                }


            }

        }

        protected void grdUsers_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void grdUsers_DataBound(object sender, EventArgs e)
        {
            int a = grdUsers.Columns.Count;
        }

        protected void grdUsers_DataBinding(object sender, EventArgs e)
        {

        }

        protected void grdUsers_RowCreated(object sender, GridViewRowEventArgs e)
        {
            int[] cols = (int[])Session["hideCols"];

            if (cols != null)
            {
                for (int i = 0; i < cols.Length; i++)
                {
                    e.Row.Cells[cols[i]].CssClass = "hiddencol";

                }
            }


        }

        protected void chkUsers_CheckedChanged(object sender, EventArgs e)
        {

        }

        protected void grdUsers_RowEditing(object sender, GridViewEditEventArgs e)
        {

        }

        protected void grdUsers_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {

        }

    }



}

